package com.springboot.file.util.easyexcel.exception;

import com.springboot.file.exception.BusinessException;
import lombok.Getter;
import java.io.Serial;

/**
 * 批处理异常类
 * 用于表示Excel批量数据处理过程中的错误
 */
@Getter
public class BatchProcessingException extends BusinessException {
    
    @Serial
    private static final long serialVersionUID = 1L;
    
    /**
     * 批次号
     */
    private final int batchNumber;
    
    /**
     * Sheet名称
     */
    private final String sheetName;
    
    /**
     * Sheet索引
     */
    private final int sheetIndex;
    
    /**
     * 起始行号
     */
    private final int startRowIndex;
    
    /**
     * 构造函数
     *
     * @param message 错误消息
     * @param batchNumber 批次号
     * @param sheetName Sheet名称
     * @param sheetIndex Sheet索引
     * @param startRowIndex 起始行号
     */
    public BatchProcessingException(String message, int batchNumber, String sheetName, int sheetIndex, int startRowIndex) {
        super(message);
        this.batchNumber = batchNumber;
        this.sheetName = sheetName;
        this.sheetIndex = sheetIndex;
        this.startRowIndex = startRowIndex;
    }
    
    /**
     * 构造函数
     *
     * @param message 错误消息
     * @param cause 原始异常
     * @param batchNumber 批次号
     * @param sheetName Sheet名称
     * @param sheetIndex Sheet索引
     * @param startRowIndex 起始行号
     */
    public BatchProcessingException(String message, Throwable cause, int batchNumber, String sheetName, int sheetIndex, int startRowIndex) {
        super(400, message);
        this.batchNumber = batchNumber;
        this.sheetName = sheetName;
        this.sheetIndex = sheetIndex;
        this.startRowIndex = startRowIndex;
        this.initCause(cause);
    }
    
    /**
     * 获取格式化的错误消息
     *
     * @return 格式化的错误消息
     */
    public String getFormattedMessage() {
        return String.format("Sheet[%d:%s] 批次%d处理失败(起始行: %d): %s", 
                sheetIndex, sheetName, batchNumber, startRowIndex, getMessage());
    }
} 